﻿@page "/Base_Manage/Base_LogException/List"

@inherits BaseList<Base_LogExceptionDTO>

<Space Size="@("small")">
    <SpaceItem>
        <Input @bind-Value="@CreatorName" Placeholder="操作人" AutoComplete=false />
    </SpaceItem>
    <SpaceItem>
        <RangePicker TValue="DateTime?[]" @bind-Value="@RangeTime" Format="yyyy-MM-dd HH:mm:ss" />
    </SpaceItem>
    <SpaceItem>
        <Search Placeholder="内容" EnterButton="true" @bind-Value="@KeyWord" OnSearch="()=>Refresh()" />
    </SpaceItem>
</Space>

<Table @ref="_table"
       TItem="Base_LogExceptionDTO"
       DataSource="Data"
       EnableVirtualization
       Loading="Loading"
       @bind-PageSize="Pagination.PageRows"
       @bind-SelectedRows="SelectedItems"       
       ScrollX="2000"
       ScrollBarWidth="12px"
       Size="TableSize.Small"
       RowClassName="@(x => x.RowIndex % 2 == 0 ?"gray-2":"")">
    <ChildContent>
        <Selection Key="@(context.Id)" />
        <AntDesign.Column Ellipsis Title="异常Id" DataIndex="EventId" TData="string" />
        <AntDesign.Column Ellipsis Title="异常名称" DataIndex="Name" TData="string" />
        <AntDesign.Column Ellipsis Title="异常消息" DataIndex="Message" TData="string" />
        <AntDesign.Column Ellipsis Title="类名称" DataIndex="ClassName" TData="string" />
        <AntDesign.Column Ellipsis Title="方法名称" DataIndex="MethodName" TData="string" />
        <AntDesign.Column Ellipsis Title="异常源" DataIndex="ExceptionSource" TData="string" />
        <AntDesign.Column Ellipsis Title="堆栈信息" DataIndex="StackTrace" TData="string" />
        <AntDesign.Column Ellipsis Title="请求参数" DataIndex="Parameters" TData="string" />
        <AntDesign.Column Ellipsis Title="操作人" DataIndex="CreatorName" TData="string" />
        <AntDesign.Column Ellipsis Title="时间" DataIndex="CreateTime" TData="DateTime" Format="yyyy-MM-dd HH:mm:ss" />
    </ChildContent>
    <PaginationTemplate>
        <div style="float:right;margin-top:10px">
            <Pagination Total="Pagination.Total"
                        ShowTotal="ShowTotal"
                        ShowSizeChanger
                        PageSize="Pagination.PageRows"
                        Current="Pagination.PageIndex"
                        OnChange="PageIndexChanged"
                        OnShowSizeChange="PageSizeChanged" />
        </div>
    </PaginationTemplate>
</Table>

<style>
    .gray-2 {
        background-color: #fafafa;
    }
</style>

@code
{
    public List()
    {
        Area = "Base_Manage";
        Condition = "Message";
    }

    string? CreatorName { get; set; }

    DateTime?[] RangeTime { get; set; } = new DateTime?[2];

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
    }

    protected override string GetDataJson()
    {
        var searchKeyValues = new Dictionary<string, object>();
        if (!string.IsNullOrEmpty(Condition) && !string.IsNullOrEmpty(KeyWord))
        {
            searchKeyValues.Add(Condition, KeyWord);
        }
        if (!string.IsNullOrEmpty(CreatorName))
        {
            searchKeyValues.Add("CreatorName", CreatorName);
        }

        var data = new
        {
            PageIndex = Pagination.PageIndex,
            PageRows = Pagination.PageRows,
            SortField = Pagination.SortField,
            SortType = Pagination.SortType,
            SearchKeyValues = searchKeyValues,
            Search = new
            {
                StartTime = RangeTime[0],
                EndTime = RangeTime[1],
            }
        };

        return data.ToJson();
    }
}